home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 1 Issue 2
/
PDCD-1 - Issue 02.iso
/
_utilities
/
utilities
/
001
/
mnemosyn
/
StubsHack
/
Sources
/
c
/
StubsHack
Wrap
Text File
|
1994-09-02
|
3KB
|
92 lines
/* ⌐ Julian Smith 1994 */
#include "kernel.h"
#include "StubsHack.StubsHack.h"
StubsHack_mallocfn StubsHack_scl_malloc = malloc;
StubsHack_freefn StubsHack_scl_free = free;
StubsHack_reallocfn StubsHack_scl_realloc = realloc;
StubsHack_callocfn StubsHack_scl_calloc = calloc;
StubsHack_fnptr StubsHack_GetDestOfB( StubsHack_fnptr address)
/* Doesn't work too well for negative ofsets, but all offsets to */
/* the shared c lib are positive. */
{
unsigned int int_address = (unsigned int) address;
unsigned int instruction = *((unsigned int *) ((int) address));
if ( (instruction & 0xFF000000) != 0xEA000000) return NULL;
instruction &= 0x00FFFFFF; /* Get the 24-bit offset. */
return (StubsHack_fnptr) ( int_address + 8/*pipeline*/ + 4*instruction);
/* This line returns a warning:
<cast>: cast between function pointer and non-function object
*/
}
StubsHack_error StubsHack_ReplaceANSIAllocFns(
StubsHack_mallocfn new_malloc,
StubsHack_reallocfn new_realloc,
StubsHack_callocfn new_calloc,
StubsHack_freefn new_free,
StubsHack_mallocfn *old_malloc_store,
StubsHack_reallocfn *old_realloc_store,
StubsHack_callocfn *old_calloc_store,
StubsHack_freefn *old_free_store,
BOOL make_stack_allocater_be_mallocfree
)
{
static BOOL firsttime = TRUE;
StubsHack_mallocfn old_malloc;
StubsHack_reallocfn old_realloc;
StubsHack_callocfn old_calloc;
StubsHack_freefn old_free;
old_malloc = (StubsHack_mallocfn) StubsHack_GetDestOfB( (StubsHack_fnptr) malloc);
old_realloc = (StubsHack_reallocfn) StubsHack_GetDestOfB( (StubsHack_fnptr) realloc);
old_calloc = (StubsHack_callocfn) StubsHack_GetDestOfB( (StubsHack_fnptr) calloc);
old_free = (StubsHack_freefn) StubsHack_GetDestOfB( (StubsHack_fnptr) free);
if ( !old_malloc || !old_realloc || !old_calloc || !old_free) return StubsHack_error_NOTSTUBS;
if (firsttime) {
StubsHack_scl_malloc = old_malloc;
StubsHack_scl_realloc = old_realloc;
StubsHack_scl_calloc = old_calloc;
StubsHack_scl_free = old_free;
}
if ( make_stack_allocater_be_mallocfree)
_kernel_register_allocs( StubsHack_scl_malloc, StubsHack_scl_free);
if (old_malloc_store) *old_malloc_store = old_malloc;
if (old_realloc_store) *old_realloc_store = old_realloc;
if (old_calloc_store) *old_calloc_store = old_calloc;
if (old_free_store) *old_free_store = old_free;
if (new_malloc) StubsHack_MakeBranchInstruction( malloc, new_malloc);
if (new_realloc) StubsHack_MakeBranchInstruction( realloc, new_realloc);
if (new_calloc) StubsHack_MakeBranchInstruction( calloc, new_calloc);
if (new_free) StubsHack_MakeBranchInstruction( free, new_free);
firsttime = FALSE;
return StubsHack_error_OK;
}